//
//  VerifyPhonePage.swift
//  Uber
//
//  Created by 朱 桓 on 16/1/18.
//  Copyright © 2016年 zhu.huan. All rights reserved.
//

import UIKit

class VerifyPhonePage: ZhBasePage {

    @IBOutlet weak var number1: UITextField!
    @IBOutlet weak var number2: UITextField!
    @IBOutlet weak var number3: UITextField!
    @IBOutlet weak var number4: UITextField!
    
    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.title = "确认手机"
        setNavigationItem("Close.png", selector: "doBack", isRight: false)
    }
    @IBAction func doEditValueChanged(sender: UITextField)
    {
        let tag = sender.tag
        
        if (sender.text!.isEmpty) {
            
            if tag - 1 > 0 {
                let preField = self.view.viewWithTag(tag-1) as! UITextField
                
                preField.becomeFirstResponder()
            }
            
        } else {
            if tag+1 <= 4 {
                let nextField = self.view.viewWithTag(tag+1) as! UITextField
                // 获取焦点
                nextField.becomeFirstResponder()
            }
        }
        
        if tag == 4 {
            // 丢失焦点
            sender.resignFirstResponder()
            doVerify()
        }
    }

    /**
    *验证方法，成功后进入主页，不成功则重新输    
    */
    func doVerify()
    {
        self.showIndicator("验证中", autoHide: true, afterDelay: true)
        self.performSelector(Selector("doShowHomePage"), withObject: nil, afterDelay: 1.0)
    }
    
    /**
    *跳转到主页面
    */
    func doShowHomePage()
    {
        let appDeg = UIApplication.sharedApplication().delegate as! AppDelegate
        
        appDeg.showHomePage()
    }
    
    override func doBack()
    {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}
